//
//  Home_ZP_01TableviewCell.m
//  MagicBox
//
//  Created by dllo on 16/8/11.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "Home_ZP_01TableviewCell.h"
#import "Home_ZP_01CollectionViewCell.h"
#import "HomePage_WebViewController.h"
@interface Home_ZP_01TableviewCell()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, retain) UICollectionView *collection;
@property (nonatomic, retain) NSMutableArray *oneArray;
@property (nonatomic, retain) NSArray *imageArr;
@end
@implementation Home_ZP_01TableviewCell

-(void)setMuArr:(NSMutableArray *)muArr{
    _muArr  = muArr;
    
    self.oneArray = [NSMutableArray array];
     self.imageArr = [NSArray arrayWithObjects:@"sale_maincate@3x.png",@"zufang_maincate@3x.png",@"house_maincate@3x.png",@"job_maincate@3x.png",@"jianzhi_maincate@3x.png",@"car_maincate@3x.png",@"pets_maincate@3x.png",@"shenghuo_maincate@3x.png",@"shangjie_maincate@3x.png",@"more_maincate@3x.png",nil];
 
    self.oneArray = muArr;
    
    
    [self creactCollection];
}

-(void)creactCollection{

    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];

    layout.itemSize = CGSizeMake(SCREENWIDTH/5,SCREENHEIGHT/9);
    layout.minimumLineSpacing  = 5;
    layout.minimumInteritemSpacing = 0;
   

    layout.minimumLineSpacing  = 0;
    layout.minimumInteritemSpacing = 0;



    self.collection = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT/4) collectionViewLayout:layout];
    self.collection.backgroundColor = [UIColor whiteColor];
    self.collection.dataSource = self;
    self.collection.delegate  = self;
    [self.contentView addSubview:self.collection];

    [self.collection registerClass:[Home_ZP_01CollectionViewCell class] forCellWithReuseIdentifier:@"oneCell"];

    
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
//     NSLog(@"%ld",self.oneArray.count);
   return self.oneArray.count;
   
}
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    Home_ZP_01CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"oneCell" forIndexPath:indexPath];

    cell.model = [self.oneArray objectAtIndex:indexPath.row];
    cell.imageStr = [self.imageArr objectAtIndex: indexPath.row];
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.item) {
        case 0:
        {
            HomePage_WebViewController *hwvc = [[HomePage_WebViewController alloc]init];
            hwvc.urlStr = @"http://app.58.com/web/salehomepage/homepage/static/sale.shtml?os=android&brand=OPPO&cversion=7.0.6.1";
            
            [[self naviController]pushViewController:hwvc animated:YES];
            
            
        }
            break;
        case 1:{
            
            
            HomePage_WebViewController *hwvc = [[HomePage_WebViewController alloc]init];
            hwvc.urlStr = @"http://app.58.com/web/list/dl/zfhouse.shtml?topcate=house&city=dl&os=android&brand=OPPO&cversion=7.0.6.1&n_city=147";
            
            [[self naviController]pushViewController:hwvc animated:YES];
        }
            break;
        case 2:{
            HomePage_WebViewController *hwvc = [[HomePage_WebViewController alloc]init];
            hwvc.urlStr = @"http://app.58.com/web/list/dl/efhouse.shtml?topcate=house&city=dl&os=android&brand=OPPO&cversion=7.0.6.1&n_city=147";
            
            [[self naviController]pushViewController:hwvc animated:YES];
            
            
        }
             break;
        case 3:{
            HomePage_WebViewController *hwvc = [[HomePage_WebViewController alloc]init];
            hwvc.urlStr = @"http://www.baidu.com";
            
            [[self naviController]pushViewController:hwvc animated:YES];
            
            
        }
             break;
        case 4:{
        
            HomePage_WebViewController *hwvc = [[HomePage_WebViewController alloc]init];
            hwvc.urlStr = @"http://www.baidu.com";
            
            [[self naviController]pushViewController:hwvc animated:YES];
        
        
        
        }
             break;
        case 5:{
            
            HomePage_WebViewController *hwvc = [[HomePage_WebViewController alloc]init];
            hwvc.urlStr = @"http://app.58.com/web/list/dl/ershouche?-20=esccate&os=android&brand=OPPO&cversion=7.0.6.1&n_city=147";
            
            [[self naviController]pushViewController:hwvc animated:YES];
        }
             break;
        case 6:{
            HomePage_WebViewController *hwvc = [[HomePage_WebViewController alloc]init];
            hwvc.urlStr = @"http://app.58.com/web/list/dl/pets.shtml?topcate=pets&os=android";
            
            [[self naviController]pushViewController:hwvc animated:YES];
        }
             break;
        case 7:{
            HomePage_WebViewController *hwvc = [[HomePage_WebViewController alloc]init];
            hwvc.urlStr = @"http://app.58.com/web/list/dl/jiazheng.shtml?formatsource=list_topcate&topcate=jiazheng&os=android";
            [[self naviController]pushViewController:hwvc animated:YES];
            
            
            
        }
             break;
        case 8:{
            HomePage_WebViewController *hwvc = [[HomePage_WebViewController alloc]init];
            hwvc.urlStr = @"http://app.58.com/web/list/dl/hyshangjie.shtml?os=android";
            
            [[self naviController]pushViewController:hwvc animated:YES];
            
        }
             break;
        case 9:{
            HomePage_WebViewController *hwvc = [[HomePage_WebViewController alloc]init];
            hwvc.urlStr = @"http://app.58.com/api/windex/api/cates?city=dl&os=android";
            
            [[self naviController]pushViewController:hwvc animated:YES];
            
            
        }
             break;
    }
    
    
    
}
- (UINavigationController*)naviController {
    
    for (UIView* next = [self superview]; next; next = next.superview) {
        
        UIResponder* nextResponder = [next nextResponder];
        
        if ([nextResponder isKindOfClass:[UINavigationController class]]) {
            
            return (UINavigationController*)nextResponder;
        }
    }
    return nil;
}








@end
